package com.study.samsung.Control.htControl;

import com.study.samsung.Entity.Classification;
import com.study.samsung.Entity.Succession;
import com.study.samsung.Service.ClassificationService;
import com.study.samsung.Service.SuccessionService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/goodscategoryedit")
public class GoodsCategoryeditServlet extends BaseServlet {
    ClassificationService cs = new ClassificationService();
    SuccessionService ss = new SuccessionService();
    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Object obj = session.getAttribute("admin");
        if (obj==null){
            return "f:htjsp/login";
        }else {
            request.setCharacterEncoding("utf-8");
            String Xid = request.getParameter("lid");
            String Xname = request.getParameter("lname");
            int i = Integer.parseInt(Xid);
            session.setAttribute("lid",i);
            session.setAttribute("lname",Xname);
            return "f:htjsp/goodscategoryedit";
        }

    }

    public String goodscategoryeditone(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String Xid = request.getParameter("xid");
        String Xname = request.getParameter("xname");
        int i = Integer.parseInt(Xid);
        session.setAttribute("xid",i);
        session.setAttribute("xname",Xname);
        return "f:htjsp/goodscategoryeditone";
    }


    public Integer changename(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String lid = request.getParameter("lid");
        String lname = request.getParameter("lname");
        int i = Integer.parseInt(lid);
        Integer changename = cs.changename(i, lname);
        return changename;
    }

    public Integer changenameone(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String xid = request.getParameter("xid");
        String xname = request.getParameter("xname");
        int i = Integer.parseInt(xid);
        Integer changename = ss.changename(i, xname);
        return changename;
    }

    public Integer addcategory(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String lname = request.getParameter("lname");
        String Xid = request.getParameter("xid");
        int xid = Integer.parseInt(Xid);
        Integer addcategory = cs.addcategory(lname,xid);
        return addcategory;
    }
    public Integer addcategoryone(HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("utf-8");
        String xname = request.getParameter("xname");
        Integer addcategory = ss.addcategory(xname);
        return addcategory;
    }

}
